package com.eqdd.yiqidian.ui.mine.qiye;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.view.View;

import com.eqdd.yiqidian.ComInviteInfoActivityCustom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.rebuild.InvitedListResultBean;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.ui.mine.unsure.MineAuPerfectActivity;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

public class ComInviteInfoActivity extends BaseActivity {
    private ComInviteInfoActivityCustom dataBinding;
    private InvitedListResultBean inviteBean;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_com_invite_info);
        initTopTitleBar(View.VISIBLE, "入职邀请");
    }

    @Override
    public void initData() {
        inviteBean = getIntent().getParcelableExtra(Config.COM_INVITE_INFO);
    }

    @Override
    public void setView() {
        dataBinding.tvComName.setText(inviteBean.getCompany());
        dataBinding.tvBumen.setText(inviteBean.getUdepartment());
        dataBinding.tvCareer.setText(inviteBean.getUpost());
        dataBinding.tvInviteName.setText(inviteBean.getInviter());
        dataBinding.tvInviteCareer.setText(inviteBean.getAdmin());
        dataBinding.tvInviteTel.setText(inviteBean.getPhone());
        if (inviteBean.getStatus() != 0) {
            dataBinding.btAccept.setVisibility(View.GONE);
            dataBinding.btReject.setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.bt_accept:
                Bundle bundle = new Bundle();
                bundle.putParcelable(Config.COM_INVITE_INFO, inviteBean);
                startActivityForResult(MineAuPerfectActivity.class, bundle, Config.MINE_AU_PERFECT);
                break;
            case R.id.bt_reject:
                OkGo.<HttpResult>post(HttpConfig.BASE_URL + HttpConfig.REJECT_COM)
                        .params("entryId", inviteBean.getId())
                        .execute(new DialogCallBack<HttpResult>(this) {
                            @Override
                            public void onSuccess(Response<HttpResult> response) {
                                HttpResult httpResult = response.body();
                                ToastUtil.showShort(httpResult.getMsg());
                                if (httpResult.getStatus() == 200) {
                                    finish();
                                }
                            }
                        });
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Config.SUCCESS) {
            switch (requestCode) {
                case Config.MINE_AU_PERFECT:
                    setResult(Config.SUCCESS);
                    finish();
                    break;
            }
        }
    }
}
